package com.cmccgz.baselibrary.view;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.cmccgz.baselibrary.R;

/**
 * 对话框
 */

public class DialogUtil {

    public static Dialog showSelectDialog(Context context, String title, final String[] items, final OnDialogItemClickListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.BottomDialog);
        builder.setTitle(title);
        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (listener != null) {
                    listener.onClick(dialog, which, items[which]);
                }
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();

        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.dialogStyle);
        window.getDecorView().setPadding(0, 0, 0, 0);



        android.view.WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;

        window.setAttributes(lp);

        return dialog;
    }

    public interface OnDialogItemClickListener {
        public void onClick(DialogInterface dialog, int which, String vaule);
    }

}
